package org.hdlh.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LoggingHandler;
import lombok.extern.slf4j.Slf4j;
import org.hdlh.codec.RpcCodec;
import org.hdlh.codec.RpcDecoder;

@Slf4j
public class RpcClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        log.info("begin client init");
        socketChannel.pipeline().addLast(
                new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,
                        12,
                        4,
                        0,
                        0))
                .addLast(new LoggingHandler())
                .addLast(new RpcCodec())
                .addLast(new RpcDecoder())
                .addLast(new RpcClientHandler());
    }
}
